﻿using System;

using System.IO;

using Configuration;
using Business.Base.Model;
using Microsoft.Office.Interop.Excel;

namespace Business.Base.Service.impl
{
    public class ExperimentExcelService
    {
        IExperimentExcelManager experimentExcelManager;

        public ExperimentExcelService(IExperimentExcelManager experimentExcelManager)
        {
            this.experimentExcelManager= experimentExcelManager;
        }


        public String SaveExperiment(Experiment experiment,String savePath = null)
        {


            String templatePath = Config.ExperimentReportTemplatePath + "\\" + experiment.ExperimentType.ToString() + "_template.xlsx";
            String saveFile = null;
            if (null == savePath)
            {
                saveFile = experiment.DefaultSavePath;
            }
            else
            {
                saveFile = savePath;
            }
            //File.Copy(templatePath, saveFile);

            /// String saveFile = null;
            Application app = new Application();
            Workbook workbook = app.Workbooks.Open(templatePath);


            experimentExcelManager.setExcel(experiment, workbook);
            app.AlertBeforeOverwriting = false;
            workbook.SaveAs(saveFile);
            workbook.Close();
            app.Quit();
            return saveFile;
        }


    }
}
